package com.gykfbxxh.imovie.base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.gykfbxxh.imovie.AppApplication;

import java.util.List;

/**
 * 所有adapter的基类
 * @author xuxinghai
 */
public abstract class AppBaseAdapter<T> extends BaseAdapter {
	public List<T> list;
	protected OnClickListener mClickListener;
	public Context context;
	public LayoutInflater inflater;
	public boolean isFastScroll;//listview是否快速滑动
	private boolean isLoadImage = false;//判断是否始终加载图片

	public AppBaseAdapter(Context context) {
		this.context = context;
		if (this.context == null) {
			inflater = LayoutInflater.from(AppApplication.getInstance());
		} else {
			inflater = LayoutInflater.from(this.context);
		}
	}

	public AppBaseAdapter(Context context, List<T> list, OnClickListener mClickListener) {
		super();
		this.list = list;
		this.mClickListener = mClickListener;
		this.context = context;
		if (this.context == null) {
			inflater = LayoutInflater.from(AppApplication.getInstance());
		} else {
			inflater = LayoutInflater.from(this.context);
		}
	}

	public void addDatas(List<T> mdatas) {
		this.list.addAll(mdatas);
	}

	public void addDatas(int index, List<T> mdatas) {
		this.list.addAll(index, mdatas);
	}

	public void setDatas(List<T> mdatas) {
		this.list.clear();
		this.list.addAll(mdatas);
	}

	public List<T> getList() {
		return list;
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	public LayoutInflater getInflater() {
		return inflater;
	}

	public void setInflater(LayoutInflater inflater) {
		this.inflater = inflater;
	}

	public boolean isLoadImage() {
		return isLoadImage;
	}

	public void setLoadImage(boolean isLoadImage) {
		this.isLoadImage = isLoadImage;
	}

	public boolean isFastScroll() {
		return isFastScroll;
	}

	public void setFastScroll(boolean isFastScroll) {
		this.isFastScroll = isFastScroll;
	}

	public AppBaseAdapter(List<T> list, Context context) {
		super();
		this.list = list;
		this.context = context;
		if (this.context == null) {
			inflater = LayoutInflater.from(AppApplication.getInstance());
		} else {
			inflater = LayoutInflater.from(this.context);
		}
	}

	@Override
	public int getCount() {
		return list != null && !list.isEmpty() ? list.size() : 0;
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return creatView(position, convertView, parent);
	}

	public abstract View creatView(int position, View convertView, ViewGroup parent);



}
